// pages/volunteer/select/index.js
const {
  getSchoolSpecialtyPage,
  planPage,
  twoMajorList,
} = require('../../../api/api')
const {
  voluntaryAdd,
  newAiMatch,
  matchCount,
  voluntarySchoolGroup,
  voluntaryConfigCity,
  viluntarySmartAdd,
  voluntaryTemplateIsVip
} = require('../../../api/ai')
const {
  decodeUserInfo
} = require('../../../api/login')
const {
  checkLogin,
  filterObj
} = require('../../../utils/util')
const selectorRouteDatas = [{
    id: 0,
    title: "省份",
    type: "checkbox",
    key: "province",
    items: []
  },
  {
    id: 1,
    title: "院校",
    type: "batch",
    key: "batch",
    items: []
  },
  {
    id: 2,
    title: "专业",
    key: "category",
    type: 'checkbox',
    items: [],
  },
  {
    id: 3,
    title: "搜索",
    key: "search",
    type: 'radiobox',
    items: [],
  },

]
const filterBatch = [{
    id: 3,
    title: "办学层次",
    key: "eduLevelName",
    type: 'radiobox',
    items: [{
        id: '本科',
        title: "本科",
      }, {
        id: '专科（高职）',
        title: "专科（高职）",
      },

    ],
  },
  {
    id: 3,
    title: "办学类型",
    key: "eduType",
    type: 'checkbox',
    items: [{
        id: '公办学校',
        title: "公办学校",
      }, {
        id: '民办学校',
        title: "民办学校",
      },
      {
        id: '中外合作办学',
        title: "中外合作办学",
      },
      {
        id: '内地港澳台合作办学',
        title: "内地港澳台合作办学",
      },
    ],
  },
  {
    id: 3,
    title: "院校特色",
    key: "schoolLabel",
    type: 'checkbox',
    items: [{
        id: 985,
        title: "985",
      }, {
        id: 211,
        title: "211",
      },
      {
        id: '双一流',
        title: "双一流",
      },
      {
        id: '强基计划',
        title: "强基计划",
      },
    ],
  },
  {
    id: 4,
    title: "院校类型",
    key: "schoolType",
    type: 'checkbox',
    items: [{
        id: '综合类',
        title: "综合类",
      }, {
        id: '理工类',
        title: "理工类",
      },
      {
        id: '农林类',
        title: "农林类",
      },
      {
        id: '医药类',
        title: "医药类",
      },
      {
        id: '师范类',
        title: "师范类",
      },
    ],
  },
]

function filterArr(selected, selectData) {
  let c = selectData.filter((item) => {
    return (selected.indexOf(item.id) > -1)
  })
  return c
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    list: [],
    selectedData: {
      province: [0],
      categoryId:[],
      category: 0,
      eduLevelName: 0,
      eduType: [],
      schoolLabel: [],
      schoolType: [],
    },
    selectorDataList: selectorRouteDatas,
    filterBatch: filterBatch,
    showSelect: false,
    type: {
      name: '本科',
      id: 2,
    },
    pageNo: 1,
    loginVisible: true,
    pageSize: 20,
    pageNoT: 1,
    filterRouteKey: "intelligenceFilters",
    batchModal: false,
    setting: {
      width: '690rpx',
      padding: '0 30rpx',
      height: '70rpx'
    },
    tabList: [{
      code: 'chong',
      text: '可冲击',
      shortText: '冲'

    }, {
      code: 'wen',
      text: '较稳妥',
      shortText: '稳'

    }, {
      code: 'bao',
      text: '可保底',
      shortText: '保'

    }, {
      code: 'all',
      text: '全部',
      shortText: ''

    }],
    list: [],
    schoolTypeList: [],
    pageSize: 10,
    detail: {},
    categoryList: [],
    loading: true,
    schoolCityScoreList: [],
    visible: false,
    bottomLift: getApp().globalData.bottomLift,
    tabIndex: 0,
    isChecked: true,
    isVisible: false,
    majorList: [],
    majorIndex: 0,
    more: false,
    listData: [{
        id: 1,
        value: '问题反馈',
        url: '/pages/users/feedback/index'
      },
      {
        id: 2,
        value: '志愿列表',
        url: '/pages/users/voluntary/index'
      }, {
        id: 3,
        value: '订单中心',
        url: '/pages/users/order/index'
      }
    ],
    setting2: {
      height: '80rpx',
      bgColor: 'rgba(0,0,0,.5)',
      color: '#ffffff',
      fontSize: '24rpx',
      align: 'center',
      top: '-260rpx',
      left: '-20rpx',
      borderRadius: '10rpx',
      contentHeight: '240rpx',
      triangle: 'bottom'
    },
    rangeIndex: 0,
    checkIndex: 0,
    range: [],
    isVip: false,
    isSvip: false,
    mode: 'batch', //院校专业组
    currentValue: null,
    total:0,
    maxValue: 170000,
    minValue: 0,
    max:170000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    // getApp().watch(this.callBack)
    if (options.params) {
      const params = JSON.parse(decodeURIComponent(options.params))
      this.setData({
        ...params,
        maxValue:params.score*1+30,
        minValue:params.score*1-30,
        max:params.score*1+30,
        min:params.score*1-30,
      })
    }
    const {
      filterRouteKey,
      selectedData
    } = this.data
    if (this.data.schoolName) {
      selectedData.search = this.data.schoolName
      this.selectComponent("#selector").setData({
        name: this.data.schoolName
      })
      this.selectComponent("#selector").schoolSearch()
    }
    wx.setStorageSync(filterRouteKey, selectedData)
    wx.removeStorageSync('categoryItem')
    // await this.getVoluntaryConfigCity()
    // this.voluntaryTemplateIsVip()
    this.fetchCategory()
    this.fetchCity()
    checkLogin().then(async res=>{
      await this.fetchUserInfo()
      await this.getVoluntarySchoolGroup()
    })
    this.getList()

  },
  inputChange(e){
      const {type}=e.target.dataset
      let value=e.detail.value
      // const {max,minValue,maxValue}=this.data
      // if(type=='maxValue' && (value<minValue || !value || value>max)){
      //   value=max
      // }
      // if(type=='minValue' && ( value>maxValue || !value)){
      //    value=0
      // }
      this.setData({
         [type]:value
      })
      this.selectComponent("#zy-slider")._propertyLeftValueChange()
      this.selectComponent("#zy-slider")._propertyRightValueChange()
  },
  minValueChange: function (e) {
    this.setData({
      minValue: e.detail.minValue
    })
  },

  maxValueChange: function (e) {
    let maxValue=e.detail.maxValue
    this.setData({
      maxValue
    })
  },
  // 查询模板是否vip
  // async voluntaryTemplateIsVip(){
  //     const {
  //     id
  //     } = this.data
  //     const {result}=await voluntaryTemplateIsVip(id)
  //     this.setData({
  //       isVip:result
  //     })
  // },
  async getVoluntaryConfigCity() {
    const {
      provinceId,
      useBatch,
      firstSelect
    } = this.data
    const params = {
      provinceId,
      firstSelect
    }
    const {
      result
    } = await voluntaryConfigCity(params)
    result.map((item) => {
      item['children'] = []
      for (var i = 0; i < item.schoolNum; i++) {
        const obj = {
          name: item.voluntaryType + (i + 1),
          specialNum: item.specialNum,
          sort: i + 1,
          // length: 0,
          localBatchName: item.localBatchName,
          voluntaryTempId: this.data.id,
          checked: false
        }
        item['children'].push(obj)
      }
    })
    const currentNavList = result.filter((item) => {
      return useBatch == item.localBatchName
    })
    const majorList = currentNavList[0].children
    const mode = currentNavList[0].specialNum > 0 ? 'batch' : 'single'
    this.setData({
      navList: result,
      majorList,
      mode
    })
  },
  async onShow() {
    checkLogin().then(async res=>{
      await this.fetchUserInfo()
    })
  },
  async fetchUserInfo() {
    const {vipType}= await getApp().fetchUserInfo()
    this.setData({
      isVip:vipType,
   })
  },
  async getVoluntarySchoolGroup() {
    const id = this.data.id
    const {
      result
    } = await voluntarySchoolGroup(id)
    const majorList = result
    const mode = result[0].specialNum > 0 ? 'batch' : 'single'
    const newList = majorList.filter((item) => {
      return item.checked == false
    })
    const majorIndex = newList.length > 0 ? parseInt(newList[0].sort) - 1 : 0
    this.setData({
      majorList,
      mode,
      majorIndex
    })
  },
  async fetchCity() {
    const {
      filterBatch,
      selectorDataList
    } = this.data
    const eduTypeList = wx.getStorageSync('edu_type') || await getApp().getDictData('edu_type')
    const schoolLabelList = wx.getStorageSync('school_label') || await getApp().getDictData('school_label')
    const schoolTypeList = wx.getStorageSync('school_type') || await getApp().getDictData('school_type')
    const cityList = wx.getStorageSync('cityList') || await getApp().getCityList()
    cityList.unshift({
      id: 0,
      title: '全国',
      checked: true
    })
    selectorDataList[0].items = cityList
    filterBatch[1].items = eduTypeList
    filterBatch[2].items = schoolLabelList
    filterBatch[3].items = schoolTypeList
    this.setData({
      filterBatch,
      selectorDataList
    })
  },
  async fetchCategory() {
    const {
      selectorDataList,
      level1Name
    } = this.data
    let params = {
      level1Name
    }
    params = filterObj(params)
    const {
      result
    } = await twoMajorList(params)
    const categoryList = result.map((item) => {
      const children = item.children.map((child) => {
        return {
          title: child.name,
          id: child.specialId
        }
      })
      // children.unshift({
      //   id: 0,
      //   title: '不限'
      // })
      return {
        id: item.specialId,
        title: item.name,
        children
      };
    })
    categoryList.unshift({
      id: 0,
      title: '全部',
      children: [{
        id: 0,
        title: '不限'
      }]
    })
    this.setData({
      categoryList,
    })
  },
  goto(e) {
    const {
      url
    } = e.currentTarget.dataset
    wx.navigateTo({
      url,
    })
  },
  async getList(newPageNo) {
    // this.setData({
    //   loading:true
    // })
    const {
      pageNo,
      pageSize,
      currentIndex,
      provinceId,
      score,
      schoolTypeList,
      ranking,
      tabList,
      selectedData,
      secondSelect,
      firstSelect,
      id,
      useBatch,
      navList,
      majorList,
      isVip,
      minValue,
      maxValue,
      max
    } = this.data
    const subjectsNames = firstSelect ? (firstSelect + ',' + secondSelect) : secondSelect
    const eduType = selectedData.eduType.join(',')
    const schoolType = selectedData.schoolType.join(',')
    let params = {
      firstSelect,
      secondSelect,
      pageNo,
      pageSize: isVip ? pageSize : 3,
      score,
      ranking,
      specialtyIds: selectedData.categoryId == 0 ?selectedData.category==0? []: []: [selectedData.categoryId],
      schoolTypeList,
      startScore:minValue,
      endScore:maxValue,
      // subjectsIds: subjectsNames,
      active: tabList[currentIndex].code,
      cityCode: provinceId, //学生所在城市
      schoolProvinceId: selectedData.province == 0 ? '' : selectedData.province, //学生选择城市
      voluntaryTempId: id,
      localBatchName: useBatch,
      schoolName: selectedData.search,
      eduType,
      eduLevelName:selectedData.eduLevelName,
      schoolType,
    }
    if (newPageNo) {
      params.pageNo = newPageNo
    }
    let obj = wx.getStorageSync('school_label_obj')
    let newObj = {}
    selectedData.schoolLabel.map(e => {
      if (obj[e]) {
        newObj[obj[e]] = 1
      }
    })
    params = Object.assign(newObj, params)
    params = filterObj(params)
    // if(max!=maxValue || minValue!=0){
    //   params.sTuition=minValue
    //   params.eTuition=maxValue
    // }
    checkLogin().then(async res=>{
      await  this.getMatchCount(params,newPageNo)
    })
  await  this.newAiMatchList(params)
    // const {
    //   result
    // } = await newAiMatch(params)
    // let chongCount=0
    // let wenCount=0
    // let baoCount=0
    // let allCount=0
    // if(result) {
    //   chongCount=result.chongCount
    //    wenCount=result.wenCount
    //    baoCount=result.baoCount
    //    allCount=result.baoCount + result.wenCount + result.chongCount
    // }
    // tabList[0]['number'] = chongCount
    // tabList[1]['number'] = wenCount
    // tabList[2]['number'] = baoCount
    // tabList[3]['number'] = allCount
    // this.setData({
    //   detail: result,
    //   // tabList,
    //   loading:false
    // })
    // var list = result && result.schoolSpecialtyVoIPage ? result.schoolSpecialtyVoIPage.records : []
    // if (list.length == 0) {return}
    // this.setData({
    //   ['list[' + (newPageNo ? newPageNo - 1 : pageNo - 1) + ']']: list,
    //   pageNo: pageNo + 1,
    //   detail: result,
    //   total:result.schoolSpecialtyVoIPage.total
    // })
  },
  // 志愿填报列表
  async newAiMatchList(params,newPageNo){
    const {
      result
    } = await newAiMatch(params)
  const {pageNo}=this.data
     this.setData({
      detail: result,
      loading:false
    })
    var list = result && result.schoolSpecialtyVoIPage ? result.schoolSpecialtyVoIPage.records : []
    list.map(e=>{
      const obj=Object.values(e.historyMap)[Object.values(e.historyMap).length-1] || {}
      e.min=obj.min
      e.minSection=obj.minSection
    })
    if (list.length == 0) {return}
    this.setData({
      ['list[' + (newPageNo ? newPageNo - 1 : pageNo - 1) + ']']: list,
      pageNo: pageNo + 1,
      detail: result,
      total:result.schoolSpecialtyVoIPage.total
    })
  },
  // 数量
 async getMatchCount(params){
    const {
      result
    } = await matchCount(params)
    const {tabList}=this.data
     let chongCount=0
    let wenCount=0
    let baoCount=0
    let allCount=0
    if(result) {
      chongCount=result.chongCount
       wenCount=result.wenCount
       baoCount=result.baoCount
       allCount=result.baoCount + result.wenCount + result.chongCount
    }
    tabList[0]['number'] = chongCount
    tabList[1]['number'] = wenCount
    tabList[2]['number'] = baoCount
    tabList[3]['number'] = allCount
     this.setData({tabList})
  },
  async load(e) {
    this.onRefresh(e.detail)
    this.getVoluntarySchoolGroup()
  },
  async single(e) {

    // await this.getList(this.data.newPageNo)
    this.onRefresh(e.detail, 'single')
    this.getVoluntarySchoolGroup()
  },
  async singleLoad(changeSort, newSort) {
    // await this.getList(this.data.newPageNo)
    this.onRefresh({
      changeSort,
      newSort
    }, 'single')
    this.getVoluntarySchoolGroup()
  },
  onRefresh(obj, type) {
    const {
      changeParams,
      list,
      majorList
    } = this.data
    const {
      changeSort,
      newSort,
      planId,
      chooseType
    } = obj
    if (newSort) {
      let changeSorts = majorList.filter((item) => {
        return item.sort == changeSort
      })
      let newSorts = majorList.filter((item) => {
        return item.sort == newSort
      })
      let newParams = this.returnIndex(newSorts[0].name)
      if (list[newParams.pindex]) {
        let newItem = list[newParams.pindex][newParams.index]
        newItem.schoolPlan.selectSort = type ? null : changeSorts[0].name
      }
      let changeItem = list[changeParams.pindex][changeParams.index]
      changeItem.schoolPlan.selectSort = newSorts[0].name
      this.setData({
        list,
      })
      return
    }
    const {
      pindex,
      index,
      schoolPlanId
    } = changeParams
    const sorts = majorList.filter((item) => {
      return item.sort == changeSort
    })
    const child = list[pindex][index]
    if (type || chooseType) {
      if (planId == schoolPlanId) {
        child.schoolPlan.selectSort = child.schoolPlan.selectSort ? null : sorts[0].name
      }
    } else {
      //院校专业组
      child.schoolPlan.selectSort = child.schoolPlan.selectSort &&
        child.schoolPlan.selectSort != sorts[0].name && newSort ? null : sorts[0].name
    }

    this.setData({
      list,
    })
  },
  returnIndex(name) {
    const {
      list
    } = this.data
    let obj = {}
    list.map((item, pindex) => {
      item.map((item, index) => {
        if (item.schoolPlan.selectSort == name) {
          obj = {
            pindex: pindex,
            index: index
          }
        }
      })
    })
    return obj
  },
  expand(e) {
    let token = wx.getStorageSync('token');
    if (!token) {
      return wx.navigateTo({url:'/pages/login/index'})
    }
    const {
      index,
      schoolid,
      value,
      sort,
      pindex,
      planid,
    } = e.currentTarget.dataset
    const {
      provinceId,
      tabList,
      currentIndex,
      selectedData,
      firstSelect,
      secondSelect,
      schoolTypeList,
      useBatch,
      minValue,maxValue
    } = this.data
    let majorIndex = 0
    if (sort) {
      majorIndex = sort.match(/\d+/g)[0] - 1
    } else {
      const {
        majorList
      } = this.data
      const newList = majorList.filter((item) => {
        return item.checked == false
      })
      majorIndex = newList.length>0? newList[0].sort - 1:0
    }
    let obj = wx.getStorageSync('school_label_obj')
    let newObj = {}
    selectedData.schoolLabel.map(e => {
      if (obj[e]) {
        newObj[obj[e]] = 1
      }
      
    })
    let params = {
        specialtyIds: selectedData.categoryId == 0 ?selectedData.category==0? []: []: [selectedData.categoryId],
        schoolTypeList,
        schoolProvinceId: selectedData.province == 0 ? '' : selectedData.province, //学生选择城市
        schoolName: selectedData.search,
        eduType:selectedData.eduType.join(','),
        eduLevelName:selectedData.eduLevelName,
        schoolType:selectedData.schoolType.join(','),
        firstSelect,
        startScore:minValue,
        endScore:maxValue,
    }
    params = Object.assign(newObj, params)
    let schoolItem = value
    schoolItem.provinceId = provinceId
    schoolItem.active = tabList[currentIndex].code
    schoolItem.params = filterObj(params)
    const changeParams = {
      pindex: pindex,
      index: index,
      schoolPlanId: planid
    }
    this.setData({
      majorIndex,
      newPageNo: pindex + 1,
      schoolItem,
      visible: true,
      schoolId: schoolid,
      changeParams
      // checkIndex: index
    })
  },
  //修改筛选条件
  filterKeyFunc() {
    const {
      filterRouteKey
    } = this.data
    const selectedData = wx.getStorageSync(filterRouteKey)
    const categoryName = wx.getStorageSync('categoryItem').title || ''
    const {
      selectorDataList
    } = this.data
    selectorDataList.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == selectedData[item.key]
      })
      const isCategory = item.key == 'category'
      const isProvince = item.key == 'province'
      item.title =isProvince?'省份':isCategory ? (categoryName || item.title) : c.length > 0 ? c[0].title : item.title
      return item
    })
    this.setData({
      selectorDataList,
      selectedData
    })
    this.getList(1)
  },
  filterKey(selectData, key, children) {
    const {
      filterRouteKey
    } = this.data
    const selectedData = wx.getStorageSync(filterRouteKey)
    var value = '';
    var array = []
    selectData.map((cate) => {
      if ((Array.isArray(selectedData[key]))) {
        cate[children].map((item) => {
          if (selectedData[key].indexOf(item.id) >= 0) {
            array.push(item)
          }
        })
      } else {
        cate[children].map((item) => {
          if (item.id == selectedData[key]) {
            value = item
          }
        })
      }
    })
    return value == '' ? array : value
  },
  async onSelectChangedRoute(e) {
    const {
      filterRouteKey
    } = this.data
    wx.setStorageSync(filterRouteKey, {
      ...e.detail
    });
    const {
      tabList
    } = this.data
    tabList[0]['number'] = 0
    tabList[1]['number'] = 0
    tabList[2]['number'] = 0
    tabList[3]['number'] = 0
    this.setData({
      pageNo: 1,
      list: [],
      tabList,
      loading:true
    })
    this.filterKeyFunc()
  },

  intelligence() {
    var that = this
    const {
      score,
      ranking,
      firstSelect,
      secondSelect,
      province,
      provinceId
    } = this.data
    const params = {
      firstSelect,
      secondSelect,
      score,
      ranking,
      province,
      provinceId
    }
    wx.navigateTo({
      url: '/pages/volunteer/intelligence/index?params=' + encodeURIComponent(JSON.stringify(params))
    })

  },
  update(e) {
    const pages = getCurrentPages()
    const prevpage = pages[pages.length - 2]
    if (prevpage.route == 'pages/volunteer/index/index') {
      wx.navigateBack()
    } else {
      wx.navigateTo({
        url: '/pages/volunteer/index/index',
      })
    }

  },
  checkItem(e) {
    const {
      type,
      value
    } = e.currentTarget.dataset
    this.setData({
      [type]: !value
    })
  },
  changeIndex(e) {
    const {
      index,
      type
    } = e.currentTarget.dataset

    if (index == this.data[type]) return

    this.setData({
      [type]: parseInt(index),
    })
    if (type !== 'currentIndex') return
    this.setData({
      pageNo: 1,
      list: [],
      loading:true
    })
    this.getList()
  },

  onReachBottom() {
    const {
      list,
      pageSize,
      pageNo,
      isVip,
      total
    } = this.data
    const count = list.length - 1
    if (list[count].length < pageSize  || (total/pageSize)==pageNo-1 || !isVip) return
    this.getList()
  },
  hide(e) {
    const {
      type
    } = e.currentTarget.dataset
    this.setData({
      [type]: false,
    })
  },
  hideModal() {
    this.setData({
      more: false,
    })
  },
  toggle(e) {
    this.hideModal()
    const {
      value,
      key
    } = e.currentTarget.dataset
    this.setData({
      [key]: !value
    })
  },
  confirm(e) {
    const value = e.detail.value
    if (value.url) {
      wx.navigateTo({
        url: value.url,
      })
    }
  },
  tuitionConfirm(){
    this.setData({
      pageNo: 1,
      list: [],
      loading:true
    })
    this.getList()
  },
  detail() {
    checkLogin().then(res=>{
      const {
        tempNo,
        firstSelect,
        secondSelect,
        provinceId,
        province,
        score,
        id
      } = this.data
      const newSecondSelect = secondSelect.replaceAll(',', '')
      const params = {
        firstSelect,
        secondSelect: newSecondSelect,
        provinceId,
        province,
        score,
        id
      }
      wx.navigateTo({
        url: '/pages/volunteer/recommend/index?tempNo=' + tempNo + '&params=' + encodeURIComponent(JSON.stringify(params)),
      })
    }).catch(e=>{
      wx.navigateTo({
        url: '/pages/login/index',
      })
    })

  },

  openPicker(e) {
    const {
      index,
      value,
      sort,
      pindex
    } = e.currentTarget.dataset
    const changeParams = {
      pindex: pindex,
      index: index
    }
    this.setData({
      changeParams,
    })
    if (sort) {
      this.setData({
        currentValue: value,
        newPageNo: pindex + 1
      })
      const a = sort.match(/\d+/g)[0]
      this.voluntaryAdd(sort.match(/\d+/g)[0])
      this.singleLoad(parseInt(a))
      return
    }
    //value为专科批学校指定的专业
    const {
      majorList
    } = this.data
    const newList = majorList.filter((item) => {
      return item.checked == false
    })
    const majorIndex = newList[0].sort - 1
    this.setData({
      rangeVisible: true,
      majorIndex,
      newPageNo: pindex + 1,
      currentValue: value,
    })
  },
  //专科切换顺序
  changeDesc(e) {
    const index = e.detail.current
    const value = e.detail.value //原来的item
    var range = e.detail.range
    var type = e.detail.type
    let _self = this
    const newItem = range[index]
    const changeSort = range[value].sort //当前sort
    const newSort = range[index].sort //被替换的sort
    if (newItem) {
      wx.showModal({
        title: '提示',
        content: newItem.name + '已经存在是否替换',
        success: async function (res) {
          if (res.confirm) {
            _self.voluntaryAdd(index + 1)
            _self.singleLoad(changeSort, newSort)
          }
        },
      })
    }

    // this.setData({
    //   majorIndex: index,
    //   majorList: range,
    //   changeItem: changeItem,
    //   originIndex: value,
    //   changeSort: type == 'origin' ? null : value + 1,
    //   newSort: index + 1
    // })
  },
  //专科保存--填报
  async rangeChange(e) {
    const index = e.detail.current
    const {
      majorList,
      currentValue
    } = this.data
    const sort = majorList[index].sort
    await this.voluntaryAdd(sort)
    this.singleLoad(sort)
  },
  async voluntaryAdd(sort) {
    const {
      currentValue,
      id,
      currentIndex,
      tabList
    } = this.data
    const params = {
      localBatchName: currentValue.schoolPlan.localBatchName,
      planId: currentValue.schoolPlan.id,
      schoolId: currentValue.schoolPlan.schoolId,
      schoolSgId: currentValue.schoolPlan.schoolSgId,
      schoolName: currentValue.schoolPlan.schoolName,
      schoolSpecialtyId: currentValue.schoolPlan.speId,
      specialtyCode: currentValue.schoolPlan.spcode,
      specialtyName: currentValue.schoolPlan.sptitle,
      sort: sort,
      matchRate: currentValue.voluntarySpecialtyScore.matchRate,
      speSort: sort,
      tempId: id,
      // active: tabList[currentIndex].code
      active: currentValue.voluntarySpecialtyScore.matchEn
    }
    const result = await voluntaryAdd(params)
    wx.showToast({
      // title: majorList[index].name + '填报成功',
      title: '填报成功',
      icon: 'none'
    })
  },
  async vip() {
    const {
      provinceId,
      score,
      firstSelect,
      secondSelect,
      province,
      ranking,
      useBatch
    } = this.data
    var params = {
      firstSelect,
      localBatchName: useBatch,
      provinceId: provinceId,
      province,
      score,
      ranking,
      secondSelect,
      year: wx.getStorageSync('year')
    }
    wx.navigateTo({
      url: '/pages/article/vip/index?params=' + encodeURIComponent(JSON.stringify(params)),
    })
  },
  onShareAppMessage() {
    return {
      title: '德道升学',
      path: '/pages/volunteer/index/index?scene=' + wx.getStorageSync('userInfo').id,
      imageUrl: 'https://ehsimg.oss-cn-beijing.aliyuncs.com/images/static/users/share_my.jpg'
    }
  }
})
